/*
 * @Author: duguangyan dis2010@126.com
 * @Date: 2024-08-22 09:13:32
 * @LastEditors: duguangyan dis2010@126.com
 * @LastEditTime: 2024-08-22 09:20:59
 * @FilePath: \sharder\src\components\side.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import React from 'react';
import Routes from '../routes';
import { Menu } from 'antd';
import { useNavigate } from "react-router-dom";
let menus = [];
Routes.forEach((item, index) => {
  let obj = {
    key: index,
    label: item.label,
  }
  if (item.children) {
    item.children.forEach((citem, i) => {
      citem.key = index + '-' + i;
    });
    obj.children = item.children
  }
  menus.push(obj);
});
export default function Side() {
  const navigate = useNavigate();
  function goPath(e) {
    let keys = e.key.split('-');
    let route, cRoute;
    route = Routes[keys[0]];
    if (route.children) {
      cRoute = route.children[keys[1]];
    }
    let path = route.path + (cRoute ? '/' + cRoute.path : '');
    navigate(path);
  }
  return <div>
    <Menu
      defaultSelectedKeys={['0']}
      defaultOpenKeys={['1']}
      mode="inline"
      theme="dark"
      items={menus}
      onClick={goPath}
    />
  </div>;
}
